<!-- 消息 -->
<template>
	<view class="wrap flex-column">
		<!-- 消息列表 -->
		<view class="msg-box">
			<uni-list v-if="userList.length>0">
				<uni-list-chat v-for="item,index in userList" :key="index" :title="item.name" :note="item.newinfo"
					:time="item.datetime" badge-positon="left" :show-badge="true" :badge-text="item.noreadcount"
					:note_type="item.infotype"
          :to="'/pages/boss/message/userMessage?option='+JSON.stringify(item)"
					:avatar="item.avatar">
				</uni-list-chat>
			</uni-list>
			<view class="" v-else>
				<sh-empty title="暂无消息"></sh-empty>
			</view>
		</view>
	</view>
</template>

<script>
  import {chatIndexgetmyxinxinuserlist} from '../../utils/userApi'
	import shEmpty from '../../components/sh/sh-empty/sh-empty.vue'
	export default {
		components: {
			shEmpty
		},
		data() {
			return {
				systemMsg: null, // 系统消息
				userList: [], // 用户消息
        page:1,
			}
		},
		async onLoad() {
			this.$websocket.setCallback((msg) => {
				let arr = this.userList
				if (msg.type == "Private") {
					let has_data_index = arr.findIndex(item => item.fromuid == msg.fromuid);
					if (has_data_index != -1) {
						arr.splice(has_data_index, 1)
					}
					arr.unshift(msg.info)
					this.userList = arr
				}
			})
		},
		async onShow() {
			await this.getUserList()
		},
		async onPullDownRefresh() {
			await this.getUserList()
			uni.stopPullDownRefresh();
		},
		methods: {
			// 获取用户消息
			async getUserList() {
				let res = await chatIndexgetmyxinxinuserlist({page:this.page})
				if (res.code == 1) {
					this.userList = res.data
				} else {
					this.page = 1
					this.userList = []
				}
			}
		},
		onReachBottom() {

		}
	}
</script>

<style lang="less">
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.input-wrap {
		width: 100%;
		height: 112rpx;
		position: sticky;
		top: 0;
		z-index: 888;
		background: #f8f8f8;
	}

	.input-box {
		height: 100%;
		flex: 1;
		background: #fff;
		height: 72rpx;

		img {
			margin: 20rpx 10rpx 20rpx 30rpx;
		}
	}

	.input-box text {
		width: 140rpx;
		height: 56rpx;
		background: #2E56EB;
		border-radius: 36rpx;
		font-family: PingFangSC, PingFang SC;
		font-size: 30rpx;
		line-height: 56rpx;
		color: #FFFFFF;
		text-align: center;
		margin-right: 6rpx;
	}

	.ipt {
		height: 100%;
		flex: 1;
	}

	.msg-box {
		flex: 1;
		height: 100%;
		background: #fff;
	}
</style>